import { defineStore } from 'pinia'
//生成随机id
import { nanoid } from 'nanoid'
import axios from 'axios'

export const useTalksStore = defineStore('talk', {
    //动作
    actions: {
         async getImg() {
            // //    let  res =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');

            // //解构做法
            // //    let {data} = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
            // //解构 再解构做法
            const { data: { content } } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
            console.log(content)
            // // 组装成对象

            const obj = { id: nanoid(), content: content }
            // //将对象压入列表 从上往下
            this.talkList.unshift(obj)
        }
    },
    //状态
    state() {
        return {
            talkList: [
                { id: 'dasdadasddsada001', content: '你今天有点怪，哪里怪？怪好看的！' },
                { id: 'dasdadasddsada002', content: '草莓、蓝莓、蔓越莓，你想我了没？' },
                { id: 'dasdadasddsada003', content: '心里给你留了一块地，我的死心塌地' }
            ]
        }

    },

    //计算
    getters: {}
})